package com.wanjia.seal.manager.controller;



import com.wanjia.seal.manager.annotation.LoginToken;
import com.wanjia.seal.manager.entity.SysMenu;
import com.wanjia.seal.manager.mapper.SysMenuMapper;
import com.wanjia.seal.manager.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Controller
@RequestMapping("/api")
@Api(tags = "菜单")
@Slf4j
public class SysMeunController extends BaseController{

    @Autowired
    SysMenuMapper sysMenuMapper;

    @ResponseBody
    @GetMapping("/allmenu")
    @ApiOperation(value = "查询所有菜单", notes = "查询是否成功")
    @LoginToken
    public JsonResult<List<SysMenu>> getAll() {
        List<SysMenu> sysMenus = sysMenuMapper.selectList(null);
        return new JsonResult<>(OK,sysMenus);
    }

    @ResponseBody
    @GetMapping("/menu")
    @ApiOperation(value = "用ID查询菜单", notes = "查询是否成功")
    @LoginToken
    public JsonResult<SysMenu> getById(Integer MenuId){
        SysMenu sysMenu = sysMenuMapper.selectById(MenuId);
        return new JsonResult<>(OK,sysMenu);
    }
    @ResponseBody
    @PutMapping("/updatemenu")
    @ApiOperation(value = "更新菜单", notes = "更新菜单是否成功")
    @LoginToken
    public JsonResult upData(@RequestBody SysMenu sysMenu){
        sysMenuMapper.updateById(sysMenu);
        return new JsonResult(OK);
    }

    @ResponseBody
    @PostMapping("/addmenu")
    @ApiOperation(value = "添加菜单", notes = "添加菜单是否成功")
    @LoginToken
    public JsonResult addRole(@RequestBody SysMenu sysMenu){
        sysMenuMapper.insert(sysMenu);
        return new JsonResult(OK);
    }
    @ResponseBody
    @DeleteMapping("/deletemenu")
    @ApiOperation(value = "删除菜单", notes = "删除菜单是否成功")
    @LoginToken
    public JsonResult update(Integer MenuId) {
        sysMenuMapper.deleteById(MenuId);
        return new JsonResult(OK);
    }

}
